home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Camelot / Camelot 043 (1989-06)(Swedish User Group of Amiga)(SE)(PD)[WB].zip / Camelot 043 (1989-06)(Swedish User Group of Amiga)(SE)(PD)[WB].adf / Glib / unix-mach.c < prev    next >
C/C++ Source or Header  |  1989-03-16  |  3KB  |  271 lines

  1. /*
  2.  * GLIB - a Generic LIBrarian and editor for synths
  3.  *
  4.  * Machine dependent stuff.
  5.  *
  6.  * Unix version
  7.  */
  8.  
  9. #include "glib.h"
  10. #include <ctype.h>
  11.  
  12. int Rows, Cols;
  13.  
  14. #include <curses.h>
  15.  
  16. hello()
  17. {
  18. }
  19.  
  20. bye()
  21. {
  22.     windgoto(22,0);
  23.     windrefresh();
  24.     windexit(0);
  25. }
  26.  
  27. /* getmouse - get currect row and column of mouse */
  28. getmouse(amr,amc)
  29. int *amr;
  30. int *amc;
  31. {
  32. #ifdef USEMOUSE
  33.     /* no such */
  34. #else
  35.     *amr = -1;
  36.     *amc = -1;
  37. #endif
  38. }
  39.  
  40. /* statmouse - return mouse button state (0=nothing pressed,1=left,2=right) */
  41. statmouse()
  42. {
  43. #ifdef USEMOUSE
  44.     /* no such */
  45. #else
  46.     return(-1);
  47. #endif
  48. }
  49.  
  50. /* Return when either a console key or mouse button is pressed. */
  51. mouseorkey()
  52. {
  53. #ifdef USEMOUSE
  54.     /* no such */
  55. #else
  56.     return(getconsole());
  57. #endif
  58. }
  59.  
  60. flushconsole()
  61. {
  62. }
  63.  
  64. statconsole()
  65. {
  66.     return(1);
  67. }
  68.  
  69. getconsole()
  70. {
  71.     return(getchar());
  72. }
  73.  
  74. getmidi()
  75. {
  76.     return(-1);
  77. }
  78.  
  79. statmidi()
  80. {
  81.     return(0);
  82. }
  83.  
  84. /*ARGSUSED*/
  85. sendmidi(c)
  86. {
  87. }
  88.  
  89. flushmidi()
  90. {
  91.     while ( STATMIDI )
  92.         getmidi();
  93. }
  94.  
  95. long milliclock()
  96. {
  97.     static long hzcount = 0;
  98.  
  99.     return(hzcount++);
  100. }
  101.  
  102. millisleep(n)
  103. {
  104.     sleep((n+500)/1000);
  105. }
  106.  
  107. char *
  108. alloc(n)
  109. {
  110.     char *p;
  111.  
  112.     if ( (p=malloc((unsigned)n)) == (char *)NULL ) {
  113.         printf("*** Whoops *** alloc has failed?!?  No more memory!\n");
  114.         fflush(stdout);
  115.         bye();
  116.     }
  117.     return(p);
  118. }
  119.  
  120. windinit()
  121. {
  122.     char *getenv();
  123.  
  124.     initscr();
  125.     Cols = 80;
  126.     Rows = 24;
  127.     noecho();
  128.     nonl();
  129.     cbreak();
  130. }
  131.  
  132. windgoto(r,c)
  133. int r,c;
  134. {
  135.     move(r,c);
  136. }
  137.  
  138. windeeol()
  139. {
  140.     clrtoeol();
  141. }
  142.  
  143. winderaserow(r)
  144. {
  145.     windgoto(r,0);
  146.     windeeol();
  147. }
  148.  
  149. windexit(r)
  150. int r;
  151. {
  152.     nocbreak();
  153.     nl();
  154.     echo();
  155.     endwin();
  156.     exit(r);
  157. }
  158.  
  159. windclear()
  160. {
  161.     clear();
  162. }
  163.  
  164. /* windgets - get a line of input from the console, handling backspaces */
  165. windgets(s)
  166. char *s;
  167. {
  168.     char *origs = s;
  169.     int c;
  170.  
  171.     while ( (c=getconsole()) != '\n' && c!='\r' && c!= EOF ) {
  172.         if ( c == '\b' ) {
  173.             if ( s > origs ) {
  174.                 windstr("\b \b");
  175.                 s--;
  176.             }
  177.         }
  178.         else {
  179.             windputc(c);
  180.             *s++ = c;
  181.         }
  182.         windrefresh();
  183.     }
  184.     *s = '\0';
  185. }
  186.  
  187. windstr(s)
  188. char *s;
  189. {
  190.     int c;
  191.  
  192.     while ( (c=(*s++)) != '\0' )
  193.         windputc(c);
  194. }
  195.  
  196. windputc(c)
  197. int c;
  198. {
  199.     addch(c);
  200. }
  201.  
  202. windrefresh()
  203. {
  204.     refresh();
  205. }
  206.  
  207. beep()
  208. {
  209.     putchar('\007');
  210. }
  211.  
  212. windhigh()
  213. {
  214.     standout();
  215. }
  216.  
  217. windnorm()
  218. {
  219.     standend();
  220. }
  221.  
  222. /****************
  223.  * openls(), nextls(), and closels() are used to scan the current directory.
  224.  ***************/
  225.  
  226. FILE *Phrlist = NULL;
  227.  
  228. openls()
  229. {
  230.     FILE *popen();
  231.     
  232.     Phrlist = popen("ls","r");
  233. }
  234. char *
  235. nextls()
  236. {
  237.     static char fname[65];
  238.  
  239.     if ( fscanf(Phrlist,"%s",fname) != 1 )
  240.         return(NULL);
  241.     return(fname);
  242. }
  243. closels()
  244. {
  245.     pclose(Phrlist);
  246. }
  247.  
  248. #ifdef FAKECBREAK
  249. #include <sys/termio.h>
  250. struct termio Initterm;
  251. static int First = 1;
  252. cbreak()
  253. {
  254.     struct termio termbuff;
  255.  
  256.     if ( First  ) {
  257.         First = 0;
  258.         ioctl(0,TCGETA,&Initterm);
  259.     }
  260.     termbuff = Initterm;
  261.     termbuff.c_lflag &= (~ICANON);
  262.     termbuff.c_cc[4] = 1;
  263.     termbuff.c_cc[5] = 1;
  264.     ioctl(0,TCSETA,&termbuff);
  265. }
  266. nocbreak()
  267. {
  268.     ioctl(0,TCSETA,&Initterm);
  269. }
  270. #endif
  271.